package com.atsebak.embeddedlinuxjvm.utils; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; public class UrlDownloader { /** * Saves a file to a path * * @param filename * @param urlString * @throws IOException */ public static void saveUrl(final String filename, final String urlString) throws IOException { BufferedInputStream in = null; FileOutputStream fout = null; try { in = new BufferedInputStream(new URL(urlString).openStream()); fout = new FileOutputStream(filename); final byte data[] = new byte[1024]; int count; while ((count = in.read(data, 0, 1024)) != -1) { fout.write(data, 0, count); } } catch (Exception e) { } finally { if (in != null) { in.close(); } if (fout != null) { fout.close(); } } } }